﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using PstBakup2013Server;
using System;

namespace Unit_Tests_PstBakup2013Server
{
    [TestClass]
    public class RequestParserTest
    {
        [TestMethod]
        public void TestParseRequest()
        {
            RequestParser parser = new RequestParser();
            RequestParser.Request parsedRequest;

            parsedRequest = parser.ParseRequest("GetAllClientsList");
            Assert.AreEqual("GetAllClientsList", parsedRequest.Command, "'GetAllClientsList' is not properly parsed.");
            Assert.AreEqual(String.Empty, parsedRequest.Parameter, "'GetAllClientsList' is not properly parsed.");

            parsedRequest = parser.ParseRequest("GetAllPstFilesForClientID:123456789-1234-1234-1234-1234567890");
            Assert.AreEqual("GetAllPstFilesForClientID", parsedRequest.Command, "'GetAllPstFilesForClientID' is not properly parsed.");
            Assert.AreEqual("123456789-1234-1234-1234-1234567890", parsedRequest.Parameter, "'GetAllPstFilesForClientID' is not properly parsed.");

            parsedRequest = parser.ParseRequest("GetAllDestinations");
            Assert.AreEqual("GetAllDestinations", parsedRequest.Command, "'GetAllDestinations' is not properly parsed.");
            Assert.AreEqual(String.Empty, parsedRequest.Parameter, "'GetAllDestinations' is not properly parsed.");

            parsedRequest = parser.ParseRequest("GetAllVersions");
            Assert.AreEqual("GetAllVersions", parsedRequest.Command, "'GetAllVersions' is not properly parsed.");
            Assert.AreEqual(String.Empty, parsedRequest.Parameter, "'GetAllVersions' is not properly parsed.");

            parsedRequest = parser.ParseRequest("GetAllClientsForVersion:1.0.1502.17");
            Assert.AreEqual("GetAllClientsForVersion", parsedRequest.Command, "'GetAllClientsForVersion' is not properly parsed.");
            Assert.AreEqual("1.0.1502.17", parsedRequest.Parameter, "'GetAllClientsForVersion' is not properly parsed.");

            parsedRequest = parser.ParseRequest("GetAllClientsForDestination:192.168.0.250");
            Assert.AreEqual("GetAllClientsForDestination", parsedRequest.Command, "'GetAllClientsForDestination' is not properly parsed.");
            Assert.AreEqual("192.168.0.250", parsedRequest.Parameter, "'GetAllClientsForDestination' is not properly parsed.");

            parsedRequest = parser.ParseRequest("GetResultIDs");
            Assert.AreEqual("GetResultIDs", parsedRequest.Command, "'GetResultIDs' is not properly parsed.");
            Assert.AreEqual(String.Empty, parsedRequest.Parameter, "'GetResultIDs' is not properly parsed.");

            parsedRequest = parser.ParseRequest(null);
            Assert.AreEqual(String.Empty, parsedRequest.Command, "null is not properly parsed.");
            Assert.AreEqual(String.Empty, parsedRequest.Parameter, "null is not properly parsed.");
        }
    }
}
